@extends('layout.default')
@section('layout.content')

  <div class="row">
    <div class="col-xs-12">
      <h4 class="header blue">{{$plan->name}}>报名情况
        <div class="pull-right">
          <a class="btn btn-sm btn-primary" href="{{route('education.enrol.create',array($plan->id))}}"><i
                class="ace-icon fa fa-plus"></i>报名</a>
          @if( isset($gid))
            <a class="btn btn-sm btn-success" href="{{route('education.enrol.export',array($plan->id, $gid))}}"><i
                  class="ace-icon fa fa-file-text-o"></i>导出</a>
          @endif
        </div>
      </h4>
    </div>
  </div>
  <div class="space-4"></div>

  <div class="row">
    <div class="col-xs-12">
      <table id="user-list" class="table table-hover table-striped table-bordered">
        <thead>
        <tr>
          <th class="center" style="width:150px;">{!!$plan->present()->categoryTitle!!}名称</th>
          <th class="hidden-480 center" style="width:80px;">帐号</th>
          <th class="align-middle" style="width:110px;">姓名</th>
          <th class="hidden-480 center" style="width:120px;">手机号码</th>
          <th class="hidden-480 center">报名日期</th>
          <th class="center" style="width:70px;">状态</th>
          <th class="center" style="width:60px;">来源</th>
          <th class="center" style="width:100px;"></th>
        </tr>
        </thead>
        <tbody>
        @foreach ($plan->grades as $grade)
          @if( count($grade->enrols) > 0)
              <?php
              $count = count($grade->enrols);
              $rowspan = $count == 1 ? '' : "rowspan='{$count}'";
              $enrol = $grade->enrols->shift();
              ?>
              <tr class="enrol" data-id="{{ $enrol->id }}">
                <td class="align-left" {!! $rowspan !!}><a
                      href="{{route('education.enrol.index', array('pid'=>$plan->id,'cid'=>$grade->id))}}">{{$grade->name}}</a>
                  <b>({{$count}})</b></td>
                <td class="smaller-80 center"><a
                      href="{{route('user.edit',array('uid'=>$enrol->user->id))}}">{{ $enrol->user->account }} </a>
                </td>
                <td class="align-middle">{!! $enrol->user->present()->face !!}<a
                      href="{{route('user.view',array('uid'=>$enrol->user->id))}}"
                      class="uid">{{ $enrol->user->name }}<span
                        style="float:right;">{!! $enrol->user->present()->props !!}</span></a>
                <td class="hidden-480 center">{{ $enrol->user->mobile }}</td>
                <td class="smaller-80 center">
                  {{ date('Y-m-d',strtotime($enrol->updated_at)) }}
                  {{ date('H:i:s',strtotime($enrol->updated_at)) }}
                </td>
                <td class="center status">{!! $enrol->present()->enrolStatus !!}</td>
                <td class="center">{!! $enrol->present()->enrolSource !!}</td>
                <td class="center">
            <span class="operate">
              <a class="sign" name="sign"><i class="ace-icon fa fa-check blue bigger-130"></i></a>&nbsp;&nbsp;
              <a class="nosign" name="nosign"><i class="ace-icon fa fa-times red bigger-130"></i></a>&nbsp;&nbsp;
              <a class="remove" name="remove"><i class="ace-icon fa fa-trash pink2 bigger-130"></i></a>
            </span>
                </td>
              </tr>
              @if($rowspan != '')
                @foreach($grade->enrols as $enrol)
                  <tr class="enrol" data-id="{{ $enrol->id }}">
                    <td class="smaller-80 center"><a
                          href="{{route('user.edit',array('uid'=>$enrol->user->id))}}">{{ $enrol->user->account }}</a>
                    </td>
                    <td class="align-middle">{!! $enrol->user->present()->face !!}<a
                          href="{{route('user.view',array('uid'=>$enrol->user->id))}}"
                          class="uid">{{ $enrol->user->name }}<span
                            style="float:right;">{!! $enrol->user->present()->props !!}</span></a>
                    <td class="hidden-480 center">{{ $enrol->user->mobile }}</td>
                    <td class="smaller-80 center">
                      {{ date('Y-m-d',strtotime($enrol->updated_at)) }}
                      {{ date('H:i:s',strtotime($enrol->updated_at)) }}
                    </td>
                    <td class="center status">{!! $enrol->present()->enrolStatus !!}</td>
                    <td class="center">{!! $enrol->present()->enrolSource !!}</td>
                    <td class="center">
                <span class="operate">
                  <a class="sign" name="sign"><i class="ace-icon fa fa-check blue bigger-130"></i></a>&nbsp;&nbsp;
                  <a class="nosign" name="nosign"><i class="ace-icon fa fa-times red bigger-130"></i></a>&nbsp;&nbsp;
                  <a class="remove" name="remove"><i class="ace-icon fa fa-trash pink2 bigger-130"></i></a>
                </span>
                    </td>
                  </tr>
                @endforeach
              @endif
          @endif
        @endforeach
        </tbody>
      </table>
    </div>
  </div>

@stop
@section('javascript')
  <script type="text/javascript">
      $(function () {


          $('.enrol').on('mouseenter', function () {
              $(this).find('.operate').show();
          }).on('mouseleave', function () {
              $(this).find('.operate').hide();
          });


          $(".sign").on('click', function () {
              var that = $(this);
              var id = that.parents(".enrol").data("id");
              var uri = "{{route('education.enrol.status',array('pid'=>$plan->id))}}";
              layer.msg('确认录取？', {
                  time: 0,
                  btn: ['确定', '取消'],
                  yes: function (index) {
                      $.post(uri, {
                          '_token': $("input[name='_token']").attr('value'),
                          'id': id,
                          'status': 2,
                          'is_submit': true
                      }, function (data) {
                          layer.msg(data.message, {time: 1000, shift: -1}, function () {
                              if (data.status === true) {
                                  that.parents().siblings(".status").html('<span class="green">录取</span>');
                              }
                          });
                      }, 'json').error(function (data) {
                          layer.msg(data.responseJSON.message);
                      });
                  }
              });

          });


          $(".nosign").on('click', function () {
              var that = $(this);
              var id = that.parents(".enrol").data("id");
              var uri = "{{route('education.enrol.status',array('pid'=>$plan->id))}}";
              //console.log(id);
              //alert(uid);
              $.post(uri, {
                  '_token': $("input[name='_token']").attr('value'),
                  'id': id,
                  'status': 0,
                  'is_submit': true
              }, function (data) {
                  layer.msg(data.message, {time: 1000, shift: -1}, function () {
                      if (data.status === true) {
                          that.parents().siblings(".status").html('<span class="red">未录取</span>');
                      }
                  });
              }, 'json').error(function (data) {
                  layer.msg(data.responseJSON.message);
              });

          });


          $(".remove").on('click', function () {
              var that = $(this);
              var id = that.parents(".enrol").data("id");
              var uri = "{{route('education.enrol.status',array('pid'=>$plan->id))}}";
              layer.msg('确认移除？', {
                  time: 0,
                  btn: ['确定', '取消'],
                  yes: function (index) {
                      $.post(uri, {
                          '_token': $("input[name='_token']").attr('value'),
                          'id': id,
                          'status': -1,
                          'is_submit': true
                      }, function (data) {
                          layer.msg(data.message, {time: 1000, shift: -1}, function () {
                              if (data.status === true) {
                                  that.parents().siblings(".status").html('<span class="red">移除</span>');
                              }
                          });
                      }, 'json').error(function (data) {
                          layer.msg(data.responseJSON.message);
                      });
                  }
              });

          });

      });
  </script>
@stop